﻿using System;
using System.Text.RegularExpressions;
using TimeMachine.Engine.Vcs;

namespace TimeMachine.Engine.Metrics.Impl
{
	[MetricDescriptor("FilesTouched")]
	public class FilesTouchedMetric : FilesOperationsMetric
	{
		public FilesTouchedMetric(ICommitsInfoProvider commitsProvider, ISourcesSettings sourcesSettings)
			: base(commitsProvider, GetIsAcceptable(sourcesSettings))
		{
		}

		private static Func<FileChangeInfo, bool> GetIsAcceptable(ISourcesSettings sourcesSettings)
		{
			Regex regex = sourcesSettings.SourceFilenameRE;
			return file => regex.IsMatch(file.Path);
		}
	}
}